<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="${ctx!}/assets/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctx!}/assets/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${ctx!}/assets/css/animate.css" rel="stylesheet">
    <link href="${ctx!}/assets/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="${ctx!}/assets/css/admin-main.css" rel="stylesheet">
    <link href="${ctx!}/assets/css/alarm.css" rel="stylesheet">

    <style>
        label {
            color: white;
        }

        .ibox-content {
            border: transparent!important;
            background-color: #12212f!important;
        }

        .ibox {
            border: transparent!important;
        }

        input, select {
            display: inline-block!important;
            width: 400px!important;
        }

        .form-group div, .form-group label {
            display: inline-block!important;
        }

        .btn-box {
            position:absolute;
            right:15px;
            bottom:5px;
        }

        .btn-box button {
            display: inline;
        }


        body {
            background-color: #12212f;
        }


    </style>

</head>

<body >
<div class="row">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-content">
                <form class="form-horizontal m-t" id="frm" method="post" action="${ctx!}/admin/user/edit">

                    <div class="form-group">
                        <label class="col-sm-3 control-label">用户角色：</label>
                        <div class="col-sm-8">
                            <select class="form_select form-control" id="role_id" name="role_id" value="">
                                        <#list roles as role>
                                            <option value=${role.id}>${role.name}</option>
                                        </#list>
                            </select>
                        </div>
                    </div>

                    <input type="hidden" id="id" name="id" value="${user.id}">

                    <div class="form-group">
                        <label class="col-sm-3 control-label">用户名：</label>
                        <div class="col-sm-8">
                            <input id="userName" name="userName" class="form-control" type="text" value="${user.userName}" <#if user?exists> readonly="readonly"</#if> >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">密码：</label>
                        <div class="col-sm-8">
                            <input id="plaintextPassword" name="plaintextPassword" class="form-control" type="text" value="${user.plaintextPassword}">
                        </div>
                    </div>


                    <div class="form-group">
                        <label class="col-sm-3 control-label">锁定状态：</label>
                        <div class="col-sm-8">
                            <select class="form_select form-control" id="locked" name="locked">
                                <option value="0" <#if user.locked==0> selected="selected" </#if> >解锁</option>
                                <option value="1" <#if user.locked==1> selected="selected" </#if> >锁定</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">备注：</label>
                        <div class="col-sm-8">
                            <input id="description" name="description" class="form-control" value="${user.description}">
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-10 col-sm-offset-3 btn-box">
                            <button class="btn btn-primary" type="submit">确认</button>
                            <button class="btn btn-primary" onclick="back()" type="reset">取消</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

</div>


<!-- 全局js -->
<script src="${ctx!}/assets/js/jquery.min.js?v=2.1.4"></script>
<script src="${ctx!}/assets/js/bootstrap.min.js?v=3.3.6"></script>

<!-- 自定义js -->
<script src="${ctx!}/assets/js/content.js?v=1.0.0"></script>

<!-- jQuery Validation plugin javascript-->
<script src="${ctx!}/assets/js/plugins/validate/jquery.validate.min.js"></script>
<script src="${ctx!}/assets/js/plugins/validate/messages_zh.min.js"></script>
<script src="${ctx!}/assets/js/plugins/layer/layer.min.js"></script>
<script src="${ctx!}/assets/js/plugins/layer/laydate/laydate.js"></script>
<script type="text/javascript">


    $(document).ready(function () {

        $("#frm").validate({
            rules: {
                role_id: {
                    required: true,
                },
                locked: {
                    required: false,
                },
                userName: {
                    required: true,
                    minlength: 4,
                    maxlength: 10
                },
                plaintextPassword: {
                    required: true,
                    minlength: 4,
                    maxlength: 20
                },
                description: {
                    required: true,
                    maxlength: 40
                }
            },
            messages: {},

            submitHandler:function(form){
                console.log($(form).serialize());
                $.ajax({
                    type: "POST",
                    dataType: "json",
                    // contentType:"application/json",
                    url: "${ctx!}/admin/user/edit",
                    data: $(form).serialize(),
                    success: function(msg){
                        layer.msg(msg.message, {time: 2000},function(){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index);
                        });
                    }
                });
            }
        });
    });
</script>

</body>

</html>
